package com.ruyuan.eshop.common.service.trade.order.impl;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.ruyuan.eshop.common.mapper.TransactionRecordMapper;
import com.ruyuan.eshop.common.domain.entity.TransactionRecordDO;
import com.ruyuan.eshop.common.service.trade.order.TransactionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 交易记录表业务类
 * @author pwd
 * @version 1.0
 */
@Service
public class TransactionRecordServiceImpl implements TransactionRecordService {

	@Autowired
	private TransactionRecordMapper transactionRecordMapper;

	/**
	 * 查询交易记录表列表
	 * @param orderSn 订单编号
	 * @return 交易记录表列表
	 */
	@Override
	public List listAll(String orderSn){

		List list = new QueryChainWrapper<>(transactionRecordMapper)
				//按订单编号查询
				.eq("order_sn", orderSn)
				//列表查询
				.list();

		return list;
	}

	/**
	 * 添加交易记录表
	 * @param transactionRecordDO 交易记录表
	 * @return TransactionRecord 交易记录表
	 */
	@Override
	@Transactional(rollbackFor=Exception.class)
	public TransactionRecordDO add(TransactionRecordDO transactionRecordDO)	{
		transactionRecordMapper.insert(transactionRecordDO);
		return transactionRecordDO;
	}

	/**
	 * 修改交易记录表
	 * @param transactionRecordDO 交易记录表
	 * @param id 交易记录表主键
	 * @return TransactionRecord 交易记录表
	 */
	@Override
	@Transactional(rollbackFor=Exception.class)
	public TransactionRecordDO edit(TransactionRecordDO transactionRecordDO, Long id){
		transactionRecordDO.setId(id);
		transactionRecordMapper.updateById(transactionRecordDO);
		return transactionRecordDO;
	}


	/**
	 * 删除交易记录表
	 * @param id 交易记录表主键
	 */
	@Override
	@Transactional(rollbackFor=Exception.class)
	public	void delete( Long id)	{
		transactionRecordMapper.deleteById(id);
	}

	/**
	 * 获取交易记录表
	 * @param id 交易记录表主键
	 * @return TransactionRecord  交易记录表
	 */
	@Override
	public TransactionRecordDO getModel(Long id)	{
		return transactionRecordMapper.selectById(id);
	}
}
